<?php
class CompanyAction extends Action {

    public function index(){

		$keys = explode(',',$seo_Arr);
		$SEO['title'] = '中国最新最全的建材求购,供应,招商,加盟信息平台-都市家建材网';
		$SEO['keywords'] = '建材,建材网,建材网站,建材新闻,建材供应,建材采购,建材招商,建材加盟,建材展会,建材企业,建材价格,建材销售,建材市场,建材产品,建材报价,建材品牌';
		$SEO['description'] = '专业提供建材产品信息,主要内容有:建材价格,建材报价,建材品牌,建材招商加盟及建材代理信息,建材商品的求购,供应,招商与合作信息;为广大建材行业的个人与企业同行们，提供海量的建材信息与商机，努力打造成国内建材行业信息免费发布平台.';
		$this->assign('SEO',$SEO);// SEO相关
	
		$Member = D('Member');
		$userid = $_SESSION[C('USER_AUTH_KEY')];

		//修改资料
		if(IS_POST){
			$data = $this->_post();
			
			$data['MemberCompany']['userid'] = $userid;
			$data['MemberCompany']['employee'] = $data['employee'];
			$data['MemberCompany']['turnover'] = $data['turnover'];
			$data['MemberCompany']['product'] = $data['product'];
			$data['MemberCompany']['introduction'] = $data['introduction'];
			$data['MemberCompany']['spaceconfig'] = $data['spaceconfig'];
			$data['MemberCompany']['address'] = $data['address'];
			$data['MemberCompany']['contact'] = $data['contact'];
			$data['MemberCompany']['homepage'] = $data['homepage'];
			$data['MemberCompany']['company'] = $data['company'];
			$data['MemberCompany']['ecompany'] = $data['ecompany'];
			$data['MemberCompany']['telephone'] = $data['telephone'];
			$data['MemberCompany']['mobilenum'] = $data['mobilenum'];
			$data['MemberCompany']['found'] = $data['found'];
			$data['MemberCompany']['domain'] = $data['domain'];
			$data['MemberCompany']['corporate'] = $data['corporate'];
			$data['MemberCompany']['catid'] = $data['catid'];
			$data['MemberCompany']['typeid'] = $data['typeid'];
			$data['MemberCompany']['province'] = $data['province'];
			$data['MemberCompany']['city'] = $data['city'];


			unset($data['corporate']);
			unset($data['employee']);
			unset($data['turnover']);
			unset($data['product']);
			unset($data['introduction']);
			unset($data['spaceconfig']);
			unset($data['address']);
			unset($data['contact']);
			unset($data['homepage']);
			unset($data['company']);
			unset($data['ecompany']);
			unset($data['telephone']);
			unset($data['mobilenum']);
			unset($data['found']);
			unset($data['domain']);
			unset($data['catid']);
			unset($data['typeid']);
			unset($data['province']);
			unset($data['city']);
			unset($data['btnSubmit']);

			
			//关联更新
			$result = $Member->relation(true)->where("userid=$userid")->save($data);
			$d = array();
			if($result === false){
				$this->ajaxReturn($d,'对不起，企业信息修改失败！',0);
			}else{
				$d = array('id'=>$userid);
				$this->ajaxReturn($d,'恭喜您，企业信息修改成功！',1);
				
			}
		
		}else{
			$data =    $Member->relation(true)->find($userid);
			//print_r($data);exit;
			if($data) {

				$this->data =   $data;// 模板变量赋值
				$this->attachment =   $data['Attachment'];// 模板变量赋值
				$Category =   M('Category');
				$condition['parentid'] = 6;
				$CateArr = $Category->field('catname,catid')->where($condition)->select(); 
				$Categoryhtml = '<option value="">请选分类</option>';
				foreach($CateArr as $Cate) {
					$Categoryhtml.= '<option value="'.$Cate['catid'].'">'.$Cate['catname'].'</option>';
				}

				$Area =   M('Area');
				$condition['parentid'] = 1;
				$AreaArr = $Area->field('name,id')->where($condition)->select(); 
				$Areahtml = '<option value="">请选省市</option>';
				foreach($AreaArr as $Cate) {
					$Areahtml.= '<option value="'.$Cate['id'].'">'.$Cate['name'].'</option>';
				}
				$this->assign('Areahtml',$Areahtml);
				$this->assign('Categoryhtml',$Categoryhtml);


				//取到大分类
				$Category =   M('Category');
				$condition['parentid'] = 6;
				$CateArr = $Category->field('catname,catid')->where($condition)->select(); 
				$Categoryhtml = '<option value="">请选分类</option>';
				foreach($CateArr as $Cate) {
					$selected = '';
					if($Cate['catid']==$data['MemberCompany']['catid']) $selected = 'selected="selected"';
					$Categoryhtml.= '<option value="'.$Cate['catid'].'" '.$selected.' >'.$Cate['catname'].'</option>';
				}

				//取到小分类
				$condition['parentid'] = $data['MemberCompany']['catid'];
				$SonCateArr = $Category->field('catname,catid')->where($condition)->select(); 
				$SonCategoryhtml = '<option value="">请选子分类</option>';
				if(is_array($SonCateArr))foreach($SonCateArr as $SonCate) {
					$selected = '';
					if($SonCate['catid']==$data['MemberCompany']['typeid']) $selected = 'selected="selected"';
					$SonCategoryhtml.= '<option value="'.$SonCate['catid'].'" '.$selected.' >'.$SonCate['catname'].'</option>';
				}



				//取到省会
				$Area =   M('Area');
				$condition['parentid'] = 1;
				$AreaArr = $Area->field('name,id')->where($condition)->select(); 
				$Areahtml = '<option value="">请选省市</option>';
				foreach($AreaArr as $Arealist) {
					$selected = '';
					if($Arealist['id']==$data['MemberCompany']['province'])  $selected = 'selected="selected"';
					$Areahtml.= '<option value="'.$Arealist['id'].'" '.$selected.' >'.$Arealist['name'].'</option>';
				}
				
				//取到市级
				$condition['parentid'] = $data['MemberCompany']['province'];
				$SonAreaArr = $Area->field('name,id')->where($condition)->select(); 
				$SonAreahtml = '<option value="">请选县区</option>';
				if(is_array($SonAreaArr))foreach($SonAreaArr as $SonArea) {
					$selected = '';
					if($SonArea['id']==$data['MemberCompany']['city']) $selected = 'selected="selected"';
					$SonAreahtml.= '<option value="'.$SonArea['id'].'" '.$selected.'>'.$SonArea['name'].'</option>';
				}
				

				$this->assign('Categoryhtml',$Categoryhtml);
				$this->assign('SonCategoryhtml',$SonCategoryhtml);
				$this->assign('Areahtml',$Areahtml);
				$this->assign('SonAreahtml',$SonAreahtml);

				

				$this->display(); // 输出模板
			}else{
				echo 'error';
			
			}
		}

    }


	//修改密码
	public function password(){
	
		$this->display(); 
	}

	
	//安全设置
	public function safeset(){
	
		$this->display(); 
	}

	
	//授权管理
	public function auth(){
	
		$this->display();
	}


	//删除信息
	public function del(){
	
		$this->display();
	}



}